package org.example.doctorapi.controller;

import org.example.doctorapi.data.HisVerificationCode;
import org.example.doctorapi.data.SysDictData;
import org.example.doctorapi.sms.VerficationCodeServiceImp;
import org.example.doctorcommon.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@RestController
@RequestMapping("/doctor/system/sms")
public class SmsSendController {
    @Autowired
    private VerficationCodeServiceImp verficationCodeServiceImp;
    @PostMapping("/sendSms/{phoneNumber}")
    public BaseResult acquireVerifyCode(@PathVariable String phoneNumber){
        int sendSms = verficationCodeServiceImp.SendSms(phoneNumber);
        return BaseResult.ok(sendSms == 1?"发送成功":"发送失败");
    }

    @GetMapping("/checjCode/{phoneNumber}/{code}")
    public BaseResult checkCode(@PathVariable String phoneNumber,
                                         @PathVariable Integer code){
        HisVerificationCode checked = verficationCodeServiceImp.checkCode(phoneNumber, code);
        if (checked != null) verficationCodeServiceImp.isCheckCode(checked);
        return BaseResult.ok(Objects.requireNonNullElse(checked, "操作失败"));
    }
}
